package com.jingdianjichi.oss.adapter.impl;

import com.jingdianjichi.oss.entity.FileInfo;
import com.jingdianjichi.oss.adapter.StorageAdapter;
import com.jingdianjichi.oss.util.MinioUtil;
import lombok.SneakyThrows;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.InputStream;
import java.util.List;

public class AliStorageAdapter implements StorageAdapter {

    @Resource
    private MinioUtil minioUtil;
    @Override
    @SneakyThrows
    public void createBuket(String bucketName) {
        minioUtil.createBuket(bucketName);
    }

    @Override
    @SneakyThrows
    public void uploadFile(MultipartFile file,String bucketName, String fileName) {
/*        minioUtil.createBuket(bucketName);
        if(fileName != null){
            minioUtil.uploadFile(file.getInputStream(), bucketName, fileName+"/");
        }else{
            minioUtil.uploadFile(file.getInputStream(), bucketName, file.getName());
        }*/
    }

    @Override
    @SneakyThrows
    public List<String> getAllBuckets() {
        return minioUtil.getAllBuckets();
    }

    @Override
    @SneakyThrows
    public List<FileInfo> getAllFiles(String buket) {
        return minioUtil.getAllFiles(buket);
    }

    @Override
    @SneakyThrows
    public InputStream downloadFile(String bucketName, String objectName) {
        return minioUtil.downloadFile(bucketName, objectName);
    }

    @Override
    @SneakyThrows
    public void deleteBucket(String bucketName) {
        minioUtil.deleteBucket(bucketName);
    }

    @Override
    @SneakyThrows
    public void deleteFile(String bucketName, String objectName) {
        minioUtil.deleteFile(bucketName, objectName);
    }

    @Override
    public String getUrl(String bucketName, String fileName) {
        return "";
    }
}
